package com.dqhl.community.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.dqhl.community.R;
import com.dqhl.community.util.Config;
import com.dqhl.community.util.ViewHolder;

import org.xutils.x;

import java.util.List;

/**
 * Created by cheng on 2016/9/10.
 * 向GridView中加载图片的adapter
 */
public class PicGridViewAdapter extends BaseAdapter {

    private Context context;
    private List<String> picList;
    private LayoutInflater inflater;

    public PicGridViewAdapter(Context context, List<String> picList) {
        this.context = context;
        this.picList = picList;
        this.inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return picList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = inflater.inflate(R.layout.item_grid_view_pic, viewGroup, false);
        }
        ImageView ivPic = ViewHolder.get(view, R.id.iv_pic);

        String picPath = picList.get(i);
        x.image().bind(ivPic, Config.Api.base_img_url + picPath);

        return view;
    }
}
